package com.freshfresh.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.freshfresh.activity.R;
import com.freshfresh.activity.classification.ProductDetailsActivity;
import com.freshfresh.utils.ImageLoadOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

public class IndexListItemEnd implements OnClickListener {
	private Context context;
	private Map<String, Object> list;
	private List<Map<String, Object>> proInfo;

	private Map<String, Object> getProInfo(int paramInt) {
		return (Map<String, Object>) this.proInfo.get(paramInt);
	}

	private void loadImg(final ImageView paramImageView, String paramString) {
		if ((paramString == null) || ("".equals(paramString)))
			return;
		ImageLoader.getInstance().displayImage(paramString, paramImageView,
				ImageLoadOptions.getOptions(0));
	}

	public View getView(Context paramContext,
			Map<String, Object> paramIndexProInfo) {
		this.context = paramContext;
		this.list = paramIndexProInfo;

		Map<String, Object> maps = (Map<String, Object>) paramIndexProInfo
				.get("product_list");
		this.proInfo = (List<Map<String, Object>>) maps.get("product_info");

		View localView = LayoutInflater.from(paramContext).inflate(
				R.layout.index_list_item5, null);
		// ((ImageView)localView.findViewById(R.id.iv_proTypeIcon)).setImageResource(paramIndexProInfo.getCategory_icon());
		((TextView) localView.findViewById(R.id.tv_proType))
				.setText(paramIndexProInfo.get("category_name").toString());
		// ((TextView)localView.findViewById(R.id.tv_proTypeDes)).setText(paramIndexProInfo.get("category_description").toString());
		TextView localTextView = (TextView) localView
				.findViewById(R.id.tv_more);
		localTextView.setTag(paramIndexProInfo.get("categoryid") + ","
				+ paramIndexProInfo.get("category_name"));
		// localTextView.setOnClickListener(this);
		ImageView localImageView = (ImageView) localView
				.findViewById(R.id.iv_pro1);
		loadImg(localImageView, getProInfo(0).get("appimage").toString());
		localImageView.setOnClickListener(this);
		localImageView.setTag(getProInfo(0).get("product_id") + ","
				+ getProInfo(0).get("sku") + ","
				+ paramIndexProInfo.get("categoryid"));
		return localView;
	}

	public void onClick(View paramView) {
		switch (paramView.getId()) {
		case R.id.tv_more:
//			String[] arrayOfString2 = paramView.getTag().toString().split(",");
//			Intent localIntent2 = new Intent(this.context,
//					ExclusiveActivity.class);
//			localIntent2.putExtra("categoryid", arrayOfString2[0]);
//			localIntent2.putExtra("name", arrayOfString2[1]);
//			this.context.startActivity(localIntent2);
			return;
		case R.id.iv_pro1:
			String[] arrayOfString1 = paramView.getTag().toString().split(",");
			Intent localIntent1 = new Intent(this.context,ProductDetailsActivity.class);
			localIntent1.putExtra("productid", arrayOfString1[0]);
			localIntent1.putExtra("sku", arrayOfString1[1]);
			localIntent1.putExtra("categoryid", arrayOfString1[2]);
			this.context.startActivity(localIntent1);
		}
	}
}